package com.jay.beiange.efccp;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.os.Handler;
import android.util.Log;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

import com.jay.beiange.efccp.contast.Constants;

/**
 * Created by Administrator on 2016/12/23.
 */

public class AppStartActivity extends Activity {
    private  Handler mHandler;
    private ImageView mSplashItem = null;
    boolean isFirstIn = false;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_app_start);
        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);
        Constants.SCREEN_DENSITY = metrics.density;
        Constants.SCREEN_HEIGHT = metrics.heightPixels;
        Constants.SCREEN_WIDTH = metrics.widthPixels;
        mHandler = new Handler(getMainLooper());
        findViewById();
        initView();
    }
    private void findViewById() {
        mSplashItem = (ImageView) findViewById(R.id.iv_splash_loading_item);
    }
    private void initView() {
        SharedPreferences preferences = getSharedPreferences(Constants.SHAREDPREFERENCES_NAME, MODE_PRIVATE);
        isFirstIn = preferences.getBoolean("isFirstIn", true);

        Animation translate = AnimationUtils.loadAnimation(this,
                R.anim.splash_loading);
        translate.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }
            @Override
            public void onAnimationRepeat(Animation animation) {

            }
            @Override
            public void onAnimationEnd(Animation animation) {
                if (!isFirstIn) {
                    goHome();
                }else{
                    goGuide();
                }

            }
        });
        Log.v("url response", "成功加载页面进入2" + translate);
        mSplashItem.setAnimation(translate);
    }

    private void goHome() {

    }

    private void goGuide() {
        Intent intent = new Intent(AppStartActivity.this,WelComeActivity.class);
        AppStartActivity.this.startActivity(intent);
        AppStartActivity.this.finish();
    }


}
